package com.ruoyi.project.module.userinfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.userinfo.domain.Userinfo;
import com.ruoyi.project.module.userinfo.service.IUserinfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 用户 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-13
 */
@Controller
@RequestMapping("/module/userinfo")
public class UserinfoController extends BaseController
{
    private String prefix = "module/userinfo";
	
	@Autowired
	private IUserinfoService userinfoService;
	
	@RequiresPermissions("module:userinfo:view")
	@GetMapping()
	public String userinfo()
	{
	    return prefix + "/userinfo";
	}
	
	/**
	 * 查询用户列表
	 */
	@RequiresPermissions("module:userinfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Userinfo userinfo)
	{
		startPage();
        List<Userinfo> list = userinfoService.selectUserinfoList(userinfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增用户
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存用户
	 */
	@RequiresPermissions("module:userinfo:add")
	@Log(title = "用户", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Userinfo userinfo)
	{		
		return toAjax(userinfoService.insertUserinfo(userinfo));
	}

	/**
	 * 修改用户
	 */
	@GetMapping("/edit/{userId}")
	public String edit(@PathVariable("userId") Integer userId, ModelMap mmap)
	{
		Userinfo userinfo = userinfoService.selectUserinfoById(userId);
		mmap.put("userinfo", userinfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存用户
	 */
	@RequiresPermissions("module:userinfo:edit")
	@Log(title = "用户", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Userinfo userinfo)
	{		
		return toAjax(userinfoService.updateUserinfo(userinfo));
	}
	
	/**
	 * 删除用户
	 */
	@RequiresPermissions("module:userinfo:remove")
	@Log(title = "用户", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(userinfoService.deleteUserinfoByIds(ids));
	}
	
}
